package api

import (
	"client/global"
	"encoding/json"
	"github.com/gin-gonic/gin"
	"github.com/olivere/elastic/v7"
	"server/proto"
	"strconv"
)

func EsHigh(c *gin.Context) {
	index := c.PostForm("index")
	word := c.PostForm("word")
	page := c.PostForm("page")
	size := c.PostForm("size")
	p, _ := strconv.Atoi(page)
	s, _ := strconv.Atoi(size)
	res, err := global.RpcClient.EsHigh(c, &proto.EsHighReq{
		Index: index,
		Word:  word,
		Page:  int64(p),
		Size:  int64(s),
	})
	var rr *elastic.SearchResult
	json.Unmarshal(res.Data, &rr)
	if err != nil {
		c.JSON(200, gin.H{
			"code": -1,
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "success",
		"data": rr,
	})
	return
}
